<template>
	<view class="container">

		<view class="tui-addr-box">
			<form :report-submit="true">
				<tui-list-cell :hover="false" padding="0">
					<view class="tui-line-cell">
						<view class="tui-title">会员昵称</view>
						<view class="tui-title">{{myName}}</view>
					</view>
				</tui-list-cell>
				<tui-list-cell :hover="false" padding="0">
					<view class="tui-line-cell">
						<view class="tui-title">手机号码</view>
						<view class="tui-title">{{myPhone}}</view>
					</view>
				</tui-list-cell>
				<tui-list-cell :hover="false" padding="0">
					<view class="tui-line-cell">
						<view class="tui-title">佳米总额</view>
						<view class="tui-title">{{myMoney}}</view>
					</view>
				</tui-list-cell>
				<tui-list-cell :hover="false" padding="0">
					<view class="tui-line-cell">
						<view class="tui-title">提现数量</view>
						<input placeholder-class="tui-phcolor" class="tui-input" name="apply_num" v-model="apply_num"
							:placeholder="feeTip" maxlength="6" type="number" />
					</view>
				</tui-list-cell>
				<tui-list-cell :hover="false" padding="0">
					<view class="tui-line-cell">
						<view class="tui-title">申请说明</view>
						<input placeholder-class="tui-phcolor" class="tui-input" name="remark" v-model="remark"
							placeholder="提现备注说明" maxlength="50" type="text" />
					</view>
				</tui-list-cell>
				
				<tui-list-cell :hover="false" padding="0">
					<view class="tui-line-cell">
						<view class="tui-title">收款码</view>
						<tui-tag size="small" type="light-green" shape="circle" class="tui-right"
							@click="uploadPayImg('wechat')">点击上传收款码</tui-tag>
					</view>
				</tui-list-cell>

				<tui-list-cell :hover="false" padding="0" v-if="showPayImg">
					<image class="qr-code" :src="payImgUrl" />
					<view class="tui-right-del">
						<tui-tag size="10px" type="danger" padding="5px 10px" shape="circle" @click="removeImg()">删除</tui-tag>
					</view>
				</tui-list-cell>


				<view class="tui-addr-save" @click="postMyMoneyApply()">
					<tui-button type="green" height="88rpx">确认申请提现</tui-button>
				</view>

				<view class="tui-protocol" hover-class="opcity" :hover-stay-time="150">
					<text class="tui-protocol-red">提现72个小时内到账~请留意你的账户信息~</text>
					<br><br>
					<text class="tui-protocol-red">单次佳米提现数量不少于3000</text>
					<br><br>
					<block v-if="shopId == 600">
					<text class="tui-protocol-red">佳米提现率1.2%，3000佳米提现36元</text>
					<br><br>
					</block>
					<text class="tui-protocol-red">请上传微信或者支付宝的收款码</text>
					<br><br><br><br><br><br>
				</view>
			</form>
		</view>
		<footer-menu :tabCur="2"></footer-menu>
	</view>
</template>

<script>
	import footerMenu from "@/components/footer-menu.vue"
	import tuiIcon from "@/components/thorui/tui-icon/tui-icon.vue"
	import tuiButton from "@/components/thorui/tui-button/tui-button"
	import tuiListView from "@/components/thorui/tui-list-view/tui-list-view"
	import tuiListCell from "@/components/thorui/tui-list-cell/tui-list-cell"
	import tuiTag from "@/components/thorui/tui-tag/tui-tag"
	const util = require('../../utils/util.js')


	export default {
		components: {
			footerMenu,
			tuiIcon,
			tuiButton,
			tuiListView,
			tuiListCell,
			tuiTag
		},
		data() {
			return {
				myName: '',
				myPhone: '',
				myMoney: '',
				apply_num: '',
				remark: '',

				payImgUrl: '',
				showPayImg: false,
				shopId: 0,
				feeTip: '单次提现不少于3000',
			}
		},
		methods: {


			getMyBaseInfo: function() {
				uni.request({
					url: this.$apiUrl + '/api/user/baseInfo',
					header: {
						'userId': uni.getStorageSync('userId'),
						'userToken': uni.getStorageSync('userToken'),
						'shopId': uni.getStorageSync('shopId')
					},
					success: (res) => {
						let resData = res.data['data'];
						this.myName = resData.name;
						this.myPhone = resData.phone;
						this.myMoney = resData.jia_mi;
					}
				});
			},


			uploadPayImg() {
				// 使用uni.chooseImage选择图片
				uni.chooseImage({
					count: 1,
					success: chooseResult => {
						// 图片选择成功后，使用uni.uploadFile上传图片
						uni.uploadFile({
							url: this.$apiUrl + '/api/common/uploadImgLocal', // 您的上传地址
							filePath: chooseResult.tempFilePaths[0],
							name: 'file', // 服务器端接收文件的字段名
							formData: {
								'user': 'test' // 如果需要额外的信息，如用户ID等
							},
							success: (uploadResult) => {
								const data = JSON.parse(uploadResult.data);
								// 根据上传结果设置图片路径
								if (data.code === 200) { // 假设成功的标志是code为200
									this.payImgUrl = data.url; // 假设返回的图片URL在data.url中
									this.showPayImg = true;
								} else {
									uni.showToast({
										title: '上传失败',
										icon: 'none'
									});
								}
							},
							fail: () => {
								uni.showToast({
									title: '上传错误',
									icon: 'none'
								});
							}
						});
					}
				});
			},

			//移除收款码
			async removeImg() {
				this.payImgUrl = '';
				this.showPayImg = false;
			},


			//提现申请
			postMyMoneyApply: function() {
				if (util.isNullOrEmpty(this.apply_num)) {
					this.tui.toast('请填写要提现的数额');
					return
				}
				if (this.apply_num < 3000) {
					this.tui.toast('单次提现不能少于3000佳米');
					return
				}
				if (Number(this.apply_num) > Number(this.myMoney)) {
					this.tui.toast('你的当前余额不足');
					return
				}
				if (util.isNullOrEmpty(this.payImgUrl)) {
					this.tui.toast('请上传收款码');
					return
				}
				if (util.isNullOrEmpty(this.remark)) {
					this.tui.toast('请输入申请说明');
					return
				}

				uni.request({
					url: this.$apiUrl + '/api/money/jiaMiApplyAdd',
					header: {
						'userId': uni.getStorageSync('userId'),
						'userToken': uni.getStorageSync('userToken'),
						'shopId': uni.getStorageSync('shopId')
					},
					data: {
						apply_num: this.apply_num,
						qr_pay_img: this.payImgUrl,
						remark: this.remark,
					},
					success: (res) => {
						let resMsg = res.data['msg'];
						let resErr = res.data['error'];
						this.tui.toast(resMsg);
						if (resErr == 0) { //发送成功的时候
							setTimeout(() => {
								uni.navigateTo({
									url: '/pages/my-money/jia-mi-bill'
								});
							}, 1000)
						}
					}
				});
			},
		},

		onLoad: function(options) {
			this.shopId = uni.getStorageSync('shopId');		//localStorage
			
			this.getMyBaseInfo();
			
			if(this.shopId == 600) {
				this.feeTip = '单次提现不少于3000';
			}
		
		},

	}
</script>

<style>
	/*tabbar*/
	.tui-tabbar {
		width: 100%;
		position: fixed;
		display: flex;
		align-items: center;
		justify-content: space-between;
		z-index: 99999;
		background: #fff;
		height: 100rpx;
		left: 0;
		bottom: 0;
		padding-bottom: env(safe-area-inset-bottom);
	}

	.tui-safearea-bottom {
		width: 100%;
		height: env(safe-area-inset-bottom);
	}

	.tui-tabbar::before {
		content: '';
		width: 100%;
		border-top: 1rpx solid #d9d9d9;
		position: absolute;
		top: 0;
		left: 0;
		-webkit-transform: scaleY(0.5);
		transform: scaleY(0.5);
	}

	.tui-tabbar-item {
		flex: 1;
		width: 25%;
		display: flex;
		align-items: center;
		flex-direction: column;
		justify-content: space-between;
		font-size: 24rpx;
		color: #666;
		height: 80rpx;
	}

	.tui-ptop-4 {
		padding-top: 4rpx;
	}

	.tui-scale {
		font-weight: bold;
		transform: scale(0.8);
		transform-origin: center 100%;
		line-height: 30rpx;
	}

	.tui-item-active {
		color: #e41f19 !important;
	}

	/*tabbar*/


	.tui-addr-box {
		padding: 20rpx 0;
	}

	.tui-line-cell {
		width: 100%;
		padding: 24rpx 30rpx;
		box-sizing: border-box;
		display: flex;
		align-items: center;
	}

	.tui-title {
		width: 180rpx;
		font-size: 28rpx;
	}

	.tui-title-city-text {
		width: 180rpx;
		height: 40rpx;
		display: block;
		line-height: 46rpx;
	}

	.tui-input {
		width: 500rpx;
	}

	.tui-input-city {
		flex: 1;
		height: 40rpx;
		font-size: 28rpx;
		padding-right: 30rpx;
	}

	.tui-phcolor {
		color: #ccc;
		font-size: 28rpx;
	}

	.tui-cell-title {
		font-size: 28rpx;
	}

	.tui-addr-label {
		margin-left: 70rpx;
	}

	.tui-label-item {
		width: 76rpx;
		height: 40rpx;
		border: 1rpx solid rgb(136, 136, 136);
		border-radius: 6rpx;
		font-size: 26rpx;
		text-align: center;
		line-height: 40rpx;
		margin-right: 20rpx;
		display: inline-block;
		transform: scale(0.9);
	}

	.tui-label-active {
		background: #E41F19;
		border-color: #E41F19;
		color: #fff;
	}

	.tui-swipe-cell {
		width: 100%;
		display: flex;
		justify-content: space-between;
		align-items: center;
		background: #fff;
		padding: 10rpx 24rpx;
		border-radius: 6rpx;
		overflow: hidden;
		font-size: 28rpx;
	}

	.tui-addr-save {
		padding: 24rpx;
		margin-top: 100rpx;
	}


	.tui-protocol {
		color: #333;
		font-size: 24upx;
		text-align: center;
		width: 100%;
		margin-top: 29upx;
	}

	.tui-protocol-red {
		color: #f54f46;
	}
	
	.qr-code{
		width: 750rpx;
		height: 1020rpx;
	}
	
	.tui-right-del{
		margin:20rpx 20rpx 100rpx 500rpx;
		padding: 40rpx;
		
	}
</style>